package cn.zyq.ykb.service.config.impl;

import cn.zyq.ykb.system.common.BaseService;
import com.github.pagehelper.PageHelper;
import cn.zyq.ykb.system.ry.util.SecurityUtils;
import cn.zyq.ykb.mapper.config.ConfigTaskTypeMapper;
import cn.zyq.ykb.beans.config.ConfigTaskType;
import cn.zyq.ykb.service.config.ConfigTaskTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.zyq.ykb.system.common.PageParam;
import com.github.pagehelper.PageInfo;


import java.time.LocalDateTime;
import java.util.List;

/**
 * 配置-任务类型Service业务层处理
 *
 * @author SystemAuth
 * @date 2023-05-29
 */
@Service
public class ConfigTaskTypeServiceImpl  extends BaseService implements ConfigTaskTypeService {

    @Autowired
    private ConfigTaskTypeMapper configTaskTypeMapper;

    /**
     * 查询配置-任务类型
     *
     * @param configTaskTypeID 配置-任务类型主键
     * @return 配置-任务类型
     */
    @Override
    public ConfigTaskType selectConfigTaskTypeByConfigTaskTypeID(Integer configTaskTypeID) {
        ConfigTaskType configTaskType = configTaskTypeMapper.selectByPrimaryKey(configTaskTypeID);
        if (configTaskType.getDeleted() == 1) {
            return null;
        }
        return configTaskType;
    }

    /**
     * 查询配置-任务类型
     *
     * @param serviceID 业务ID
     * @return 配置-任务类型
     */
    @Override
    public ConfigTaskType selectConfigTaskTypeByServiceID(String serviceID) {
        ConfigTaskType param = new ConfigTaskType();
        param.setDeleted(0);
        param.setServiceID(serviceID);
        return this.configTaskTypeMapper.selectOne(param);
    }

    /**
     * 查询配置-任务类型列表
     *
     * @param pageParam
     * @return 配置-任务类型
     */
    @Override
    public PageInfo<ConfigTaskType> selectConfigTaskTypeList(PageParam pageParam) {
        PageHelper.startPage(pageParam.getPage(), pageParam.getPageSize());
        pageParam.getKv().put("deleted", 0);
        List<ConfigTaskType> list = this.configTaskTypeMapper.list(pageParam.getKv());
        return new PageInfo<>(list);
    }

    /**
     * 查询配置-任务类型列表
     *
     * @param param
     * @return 配置-任务类型
     */
    @Override
    public List<ConfigTaskType> selectConfigTaskTypeList(ConfigTaskType param) {
        param.setDeleted(0);
        return this.configTaskTypeMapper.select(param);
    }
    /**
     * 新增配置-任务类型
     *
     * @param param 配置-任务类型
     * @return 结果
     */
    @Override
    public int insertConfigTaskType(ConfigTaskType param) {
        this.setCreateBaseData(param, SecurityUtils.getLoginUser().getSysAdmin());
        return this.configTaskTypeMapper.insertSelective(param);
    }

    /**
     * 修改配置-任务类型
     *
     * @param param 配置-任务类型
     * @return 结果
     */
    @Override
    public int updateConfigTaskType(ConfigTaskType param) {
        this.setUpdateBaseData(param, SecurityUtils.getLoginUser().getSysAdmin());
        return this.configTaskTypeMapper.updateByPrimaryKeySelective(param);
    }

    /**
     * 批量删除配置-任务类型
     *
     * @param configTaskTypeIDs 需要删除的配置-任务类型主键
     * @return 结果
     */
    @Override
    public int deleteConfigTaskTypeByConfigTaskTypeIDs(Integer[] configTaskTypeIDs) {
        int i = 0;
        for (Integer configTaskTypeID : configTaskTypeIDs) {
            i += this.deleteConfigTaskTypeByConfigTaskTypeID(configTaskTypeID);
        }
        return i;
    }

    /**
     * 删除配置-任务类型信息
     *
     * @param configTaskTypeID 配置-任务类型主键
     * @return 结果
     */
    @Override
    public int deleteConfigTaskTypeByConfigTaskTypeID(Integer configTaskTypeID) {
        ConfigTaskType configTaskType = this.selectConfigTaskTypeByConfigTaskTypeID(configTaskTypeID);
        if (configTaskType == null) {
            return 0;
        } else {
            ConfigTaskType storeInfo = new ConfigTaskType();
            storeInfo.setConfigTaskTypeID(configTaskTypeID);
            storeInfo.setDeleted(1);
            storeInfo.setUpdateBy(SecurityUtils.getSysAdminID());
            storeInfo.setUpdateTime(LocalDateTime.now());
            this.configTaskTypeMapper.updateByPrimaryKeySelective(storeInfo);
            return 1;
        }
    }
}
